package com.wx.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.wx.springcloud.alibaba.handler.CustomBlockHandler;
import com.wx.springcloud.entities.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangdada
 */
@RestController
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
        return "....testA";
    }

    @GetMapping("/testB")
    public String testB() {
        return "....testB";
    }

    @GetMapping("/testHotkey")
    @SentinelResource(value = "testHotKey", blockHandler = "dealHandler_testHotkey")
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
                             @RequestParam(value = "p2", required = false) String p2) {
        return "-----testHotKey";
    }

    public String dealHandler_testHotkey(String p1, String p2, BlockException blockException) {
        return "----dealHandler_testHotkey";
    }

    @GetMapping("/rateLimit/customerBlockHandler")
    @SentinelResource(value = "customerBlockHandler", blockHandlerClass = CustomBlockHandler.class, blockHandler = "handleException")
    public CommonResult customBlockHandler(){
        return new CommonResult(200,"自定义限流处理处理逻辑");
    }
}
